package com.vanysoft.business.system.init.controller;

import com.vanysoft.business.system.init.controller.demo.RootOrgSetObj;
import com.vanysoft.business.system.init.service.SystemInitService;
import com.vanysoft.framework.base.action.BaseController;
import com.vanysoft.framework.exception.VanySoftBaseException;
import com.vanysoft.framework.messagesource.MessageCodeConstant;
import com.vanysoft.framework.utils.JSONResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * 类名称：SystemInitAction
 * 类描述：系统初始化(安装向导)控制类
 * 创建人：X
 * 创建时间：2017年9月2日上午7:56:04
 * 修改人：X
 * 修改时间：2017年9月2日
 * 版本信息：@version 1.0
 * Copyright (c) 2017SharpClaw-版权所有
 * 修改备注：
 */
@RestController
@RequestMapping("/system/init")
public class SystemInitAction extends BaseController {

    @Autowired
    private SystemInitService systemInitService;

    /**
     * Function Name               initSystem
     *
     * @return
     * @throws VanySoftBaseException
     * @description 初始化系统设置
     * Modify History:              Date             Programmer       Notes
     * ---------        ---------------  ---------
     * 2017年9月19日上午10:07:27          X          Initial
     * *********************************************************************
     */
    @RequestMapping(value = "/initSys", method = RequestMethod.POST)
    public JSONResponse initSystem(HttpServletRequest request, @Valid RootOrgSetObj inputObj, BindingResult result) throws VanySoftBaseException {
        Map<String, Object> map = new HashMap<String, Object>();
        boolean b = false;
        b = systemInitService.initSystemTable();
        b = systemInitService.initSystemData(inputObj);
        String isOk = "NO";
        if (b) isOk = "OK";
        map.put("isOk", isOk);
        return new JSONResponse(MessageCodeConstant.RTN_CODE_SUCCESS, map);
    }

}
